package com.zhang.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.zhang.service.ShoppingCarService;
import com.zhang.units.Result;
import com.zhang.vo.AddProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZhangD
 * @since 2021-07-13
 */
@RestController
public class ShoppingCarController {

    @Autowired
    private ShoppingCarService shoppingCarService;

    /**
     * 向购物车添加商品
     */
    @PostMapping("/addProduct" )
    public Result addProductByUserId(@RequestBody AddProductVo addProductVo){
        shoppingCarService.addProductByAddProduct(addProductVo);
        return Result.result200();
    }

    /**
     * 删除商品
     */
    @GetMapping("/delete/product")
    public Result deleteProductById(@RequestParam("pid") String pid){
        shoppingCarService.deleteProuductById(pid);
        return Result.result200();
    }

    /**
     * 清空购物车
     */
    @GetMapping("/delete/productAll")
    public  Result deleteAllProductByUserId(@RequestParam("uid") String uid){
        shoppingCarService.deleteAllProductByUserId(uid);
        return Result.result200();
    }


}

